#include "../../include/car_parts/battery.h"
Battery::Battery()
{
    this->parameters = "24V/15Ah";
    this->outputVoltage = 24;
    this->chargingTime = 2;
}
void Battery::setParameters(const std::string &parameters)
{
    this->parameters = parameters;
}

void Battery::setOutputVoltage(double outputVoltage)
{
    this->outputVoltage = outputVoltage;
}

void Battery::setChargingTime(double chargingTime)
{
    this->chargingTime = chargingTime;
}
// 屏幕输出
void Battery::print()
{
    std::cout << "**电池模块**"
              << "\n电池充电时长(h): " << chargingTime << "\n对外供电(V): " << outputVoltage << "\n参数: " << parameters << std::endl;
}
// 本地文件保存
void Battery::save(const std::string &filename)
{
    // 打开一个输出文件流
    std::ofstream file(filename, std::ios::app);
    if (!file.is_open())
    {
        std::cout << "未找到文件！" << std::endl;
        return;
    }

    file << "," << chargingTime << "," << outputVoltage << "," << parameters;

    // 关闭文件流
    file.close();
}